import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
import { Link } from 'element-ui'

/**
 * Note: 路由配置项
 *
 * hidden: true                     // 当设置 true 的时候该路由不会再侧边栏出现 如401，login等页面，或者如一些编辑页面/edit/1
 * alwaysShow: true                 // 当你一个路由下面的 children 声明的路由大于1个时，自动会变成嵌套的模式--如组件页面
 *                                  // 只有一个时，会将那个子路由当做根路由显示在侧边栏--如引导页面
 *                                  // 若你想不管路由下面的 children 声明的个数都显示你的根路由
 *                                  // 你可以设置 alwaysShow: true，这样它就会忽略之前定义的规则，一直显示根路由
 * redirect: noRedirect             // 当设置 noRedirect 的时候该路由在面包屑导航中不可被点击
 * name:'router-name'               // 设定路由的名字，一定要填写不然使用<keep-alive>时会出现各种问题
 * query: '{"id": 1, "name": "ry"}' // 访问路由的默认传递参数
 * roles: ['admin', 'common']       // 访问路由的角色权限
 * permissions: ['a:a:a', 'b:b:b']  // 访问路由的菜单权限
 * meta : {
    noCache: true                   // 如果设置为true，则不会被 <keep-alive> 缓存(默认 false)
    title: 'title'                  // 设置该路由在侧边栏和面包屑中展示的名字
    icon: 'svg-name'                // 设置该路由的图标，对应路径src/assets/icons/svg
    breadcrumb: false               // 如果设置为false，则不会在breadcrumb面包屑中显示
    activeMenu: '/system/user'      // 当路由设置了该属性，则会高亮相对应的侧边栏。
  }
 */

// 公共路由

export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect')
      }
    ]
  },
  {
    path: '/',
    component: Layout,
    redirect: '/login',
    hidden: true
  },
  {
    path: '/myCenter',
    name: 'myCenter',
    component: Layout,
    redirect: '/myCenter/table',
    title: '个人中心',
    icon: 'el-icon-message-solid',
    meta: { title: '个人中心', icon: 'el-icon-message-solid' },
    children: [
      {
        path: 'myCenter',
        name: 'MyCenter',
        title: '个人信息',
        icon: 'el-icon-message',
        component: () => import('@/views/myCenter/info'),
        meta: { title: '个人信息', icon: 'dashboard', roles: ['level_1', 'level_2']}
      },
      {
        path: 'message',
        name: 'Message',
        title: '消息设置',
        icon: 'el-icon-message',
        component: () => import('@/views/myCenter/message'),
        meta: { title: '消息设置', icon: 'dashboard', roles: ['level_1', 'level_2']}
      },{
        path: 'tempDept',
        name: 'TempDept',
        title: '临时部门申请',
        icon: 'el-icon-message',
        component: () => import('@/views/myCenter/tempDept'),
        meta: { title: '临时部门申请', icon: 'dashboard', roles: ['level_1', 'level_2']}
      },
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login'),
    hidden: true
  },
  
]

export const asyncRoutes = [
  {
    id: 25,
    path: '/guidance',
    component: Layout,
    redirect: '/guidance/table',
    name: 'guidance',
    title: '治疗',
    icon: 'el-icon-s-custom',
    meta: { title: '治疗', icon: 'example' },
    children: [
      ,{
        id: 27,
        path: 'patient',
        name: 'Patient',
        title: '会员设置',
        icon: 'el-icon-s-custom',
        component: () => import('@/views/guidance/patient'),
        meta: { title: '会员设置', icon: 'table' },
      },{
        id: 46,
        path: 'guidanceRegister',
        name: 'GuidanceRegister',
        title: '挂号',
        icon: 'el-icon-s-check',
        component: () => import('@/views/guidance/guidanceRegister'),
        meta: { title: '挂号', icon: 'table' },
      },{
        id: 29,
        path: 'guidancePage',
        name: 'GuidancePage',
        title: '挂号详情',
        icon: 'table',
        component: () => import('@/views/guidance/guidancePage'),
        meta: { title: '挂号详情', icon: 'table' },
        hidden: true,
      },{
        id: 30,
        path: 'guidanceList',
        name: 'GuidanceList',
        title: '诊前处置',
        icon: 'el-icon-s-check',
        component: () => import('@/views/guidance/guidanceList'),
        meta: { title: '诊前处置', icon: 'table' },
      },{
        id: 48,
        path: 'visitList',
        name: 'VisitList',
        title: '诊中处置',
        icon: 'el-icon-s-check',
        component: () => import('@/views/guidance/visitList'),
        meta: { title: '诊中处置', icon: 'table' },
      },{
        id: 41,
        path: 'visitPage',
        name: 'VisitPage',
        title: '就诊页',
        icon: 'el-icon-s-check',
        component: () => import('@/views/guidance/visitPage'),
        meta: { title: '就诊页', icon: 'table' },
        hidden: true,
      },{
        id: 49,
        path: 'paid',
        name: 'Paid',
        title: '办卡缴费',
        icon: 'el-icon-s-check',
        component: () => import('@/views/guidance/paid'),
        meta: { title: '办卡缴费', icon: 'table' },
      },{
        id: 50,
        path: 'checkup',
        name: 'Checkup',
        title: '实验室检查处置',
        icon: 'el-icon-s-check',
        component: () => import('@/views/guidance/checkup'),
        meta: { title: '实验室检查处置', icon: 'table' },
      },{
        id: 51,
        path: 'takeDrug',
        name: 'TakeDrug',
        title: '取药处置',
        icon: 'el-icon-s-check',
        component: () => import('@/views/guidance/takeDrug'),
        meta: { title: '取药处置', icon: 'table' },
      },{
        id: 52,
        path: 'otherVisit',
        name: 'OtherVisit',
        title: '邮寄/代取/代放处置',
        icon: 'el-icon-s-check',
        component: () => import('@/views/guidance/otherVisit'),
        meta: { title: '邮寄/代取/代放处置', icon: 'table' },
      },{
        id: 53,
        path: 'rentingBox',
        name: 'RentingBox',
        title: '租盒处置',
        icon: 'el-icon-s-check',
        component: () => import('@/views/guidance/rentingBox'),
        meta: { title: '租盒处置', icon: 'table' },
      },{
        id: 54,
        path: 'callBack',
        name: 'CallBack',
        title: '回访处置',
        icon: 'el-icon-s-check',
        component: () => import('@/views/guidance/callBack'),
        meta: { title: '回访处置', icon: 'table' },
      },{
        id: 55,
        path: 'vip',
        name: 'Vip',
        title: '会员等级设置',
        icon: 'el-icon-s-check',
        component: () => import('@/views/guidance/vip'),
        meta: { title: '会员等级设置', icon: 'table' },
      },{
        id: 56,
        path: 'voucher',
        name: 'Voucher',
        title: '卡/券/活动设置',
        icon: 'el-icon-s-check',
        component: () => import('@/views/guidance/voucher'),
        meta: { title: '卡/券/活动设置', icon: 'table' },
      },{
        id: 26,
        path: 'source',
        name: 'Source',
        title: '来源管理',
        icon: 'el-icon-bottom-right',
        component: () => import('@/views/guidance/source'),
        meta: { title: '来源管理', icon: 'table' }
      },{
        id: 28,
        path: 'template',
        name: 'Template',
        title: '导诊模板管理',
        icon: 'el-icon-s-grid',
        component: () => import('@/views/guidance/template'),
        meta: { title: '导诊模板管理', icon: 'table' }
      },{
        id: 40,
        path: 'visitTemplateJobOffice',
        name: 'VisitTemplateJobOffice',
        title: '执业科室-就诊模板管理',
        icon: 'el-icon-s-grid',
        component: () => import('@/views/guidance/visitTemplateJobOffice'),
        meta: { title: '执业科室-就诊模板管理', icon: 'table' }
      },{
        id: 39,
        path: 'visitTemplateList',
        name: 'VisitTemplateList',
        title: '就诊模板管理',
        icon: 'el-icon-s-grid',
        component: () => import('@/views/guidance/visitTemplateList'),
        meta: { title: '就诊模板管理', icon: 'table' }
      },{
        id: 38,
        path: 'visitTemplate',
        name: 'VisitTemplate',
        title: '就诊模板页',
        icon: 'el-icon-s-grid',
        component: () => import('@/views/guidance/visitTemplate'),
        meta: { title: '就诊模板页', icon: 'table' },
        hidden: true,
      },
    ]
  },
  {
    id: 4,
    path: '/store',
    component: Layout,
    redirect: '/store/table',
    name: 'store',
    title: '仓库管理',
    icon: 'el-icon-s-shop',
    meta: { title: '仓库管理', icon: 'example' },
    children: [
      // {
      //   id: 6,
      //   path: 'purchaseOrder',
      //   name: 'purchaseOrder',
      //   title: '临采单',
      //   icon: 'el-icon-s-order',
      //   component: () => import('@/views/drug/purchaseOrder'),
      //   meta: { title: '临采单', icon: 'table', roles: ['level_2'] },
      // },
      // {
      //   id: 36,
      //   path: 'purchaseOrderAll',
      //   name: 'purchaseOrderAll',
      //   title: '集采单',
      //   icon: 'el-icon-s-order',
      //   component: () => import('@/views/drug/purchaseOrderAll'),
      //   meta: { title: '集采单', icon: 'table' },
      // },
      // {
      //   id: 37,
      //   path: 'purchasePage',
      //   name: 'purchasePage',
      //   title: '集采页',
      //   icon: 'table',
      //   component: () => import('@/views/drug/purchasePage'),
      //   meta: { title: '集采页', icon: 'table' },
      //   hidden: true,
      // },
      {
        id: 21,
        path: 'input',
        name: 'Input',
        title: '入库',
        icon: 'el-icon-shopping-cart-full',
        component: () => import('@/views/drug/input'),
        meta: { title: '入库', icon: 'table', roles: ['level_2'] }
      },
      {
        id: 45,
        path: 'exchange',
        name: 'Exchange',
        title: '调库单',
        icon: 'el-icon-shopping-cart-full',
        component: () => import('@/views/drug/exchange'),
        meta: { title: '调库单', icon: 'table', roles: ['level_2'] }
      },{
        id: 47,
        path: 'cancelDepository',
        name: 'CancelDepository',
        title: '返库单',
        icon: 'el-icon-shopping-cart-full',
        component: () => import('@/views/drug/cancelDepository'),
        meta: { title: '返库单', icon: 'table', roles: ['level_2'] }
      },
      {
        id: 42,
        path: 'drugDepositoryAuth',
        name: 'DrugDepositoryAuth',
        title: '库权限管理',
        icon: 'el-icon-shopping-cart-full',
        component: () => import('@/views/drug/drugDepositoryAuth'),
        meta: { title: '库权限管理', icon: 'table', roles: ['level_2'] }
      },
      {
        id: 34,
        path: 'check',
        name: 'Check',
        title: '盘点',
        icon: 'el-icon-shopping-cart-full',
        component: () => import('@/views/drug/check'),
        meta: { title: '盘点', icon: 'table', roles: ['level_2'] }
      },
      {
        id: 35,
        path: 'checkPage',
        name: 'CheckPage',
        title: '盘点页',
        icon: 'table',
        component: () => import('@/views/drug/checkPage'),
        meta: { title: '盘点页', icon: 'table' },
        hidden: true,
      },
      
      {
        id: 43,
        path: 'writeOff',
        name: 'WriteOff',
        title: '盘点审核',
        icon: 'el-icon-shopping-cart-full',
        component: () => import('@/views/drug/writeOff'),
        meta: { title: '盘点审核', icon: 'table', roles: ['level_2'] }
      },
      {
        id: 44,
        path: 'writeOffPage',
        name: 'WriteOffPage',
        title: '核销页',
        icon: 'el-icon-shopping-cart-full',
        component: () => import('@/views/drug/writeOffPage'),
        meta: { title: '核销页', icon: 'table', roles: ['level_2'] },
        hidden: true,
      },
      {
        id: 22,
        path: 'supplier',
        name: 'Supplier',
        title: '供货商管理',
        icon: 'el-icon-phone',
        component: () => import('@/views/drug/supplier'),
        meta: { title: '供货商管理', icon: 'table', roles: ['level_2']}
      },
      {
        id: 32,
        path: 'factory',
        name: 'Factory',
        title: '厂家管理',
        icon: 'el-icon-school',
        component: () => import('@/views/drug/factory'),
        meta: { title: '厂家管理', icon: 'table', roles: ['level_2']}
      },
      {
        id: 23,
        path: 'depository',
        name: 'Depository',
        title: '库房管理',
        icon: 'el-icon-s-home',
        component: () => import('@/views/drug/depository'),
        meta: { title: '库房管理', icon: 'table', roles: ['level_2']}
      },
      {
        id: 24,
        path: 'inventory',
        name: 'Inventory',
        title: '库存查询',
        icon: 'el-icon-edit-outline',
        component: () => import('@/views/drug/inventory'),
        meta: { title: '库存查询', icon: 'table', roles: ['level_2']}
      },
      {
        id: 5,
        path: 'drugList',
        name: 'DrugList',
        title: '物品档案',
        icon: 'el-icon-files',
        component: () => import('@/views/drug/list'),
        meta: { title: '物品档案', icon: 'table', roles: ['level_2']}
      },
      {
        id: 7,
        path: 'drugType',
        name: 'DrugType',
        title: '物品类型',
        icon: 'el-icon-notebook-2',
        component: () => import('@/views/drug/type'),
        meta: { title: '物品类型', icon: 'table', roles: ['level_2']}
      },
      {
        id: 31,
        path: 'drugTag',
        name: 'DrugTag',
        title: '标签管理',
        icon: 'el-icon-price-tag',
        component: () => import('@/views/drug/tag'),
        meta: { title: '标签管理', icon: 'table', roles: ['level_2']}
      },
    ]
  },
  {
    id: 8,
    path: '/dept',
    component: Layout,
    redirect: '/dept/table',
    name: 'dept',
    title: '部门管理',
    icon: 'el-icon-office-building',
    meta: { title: '部门管理', icon: 'example' },
    children: [
      {
        id: 33,
        path: 'tmpDeptList',
        name: 'TmpDeptList',
        title: '临时部门管理',
        icon: 'el-icon-film',
        component: () => import('@/views/dept/tmpDeptList'),
        meta: { title: '临时部门管理', icon: 'table' }
      },
      {
        id: 9,
        path: 'deptList',
        name: 'DeptList',
        title: '部门设置',
        icon: 'el-icon-film',
        component: () => import('@/views/dept/index'),
        meta: { title: '部门设置', icon: 'table' }
      },
      {
        id: 10,
        path: 'jobDuty',
        name: 'JobDuty',
        title: '职务设置',
        icon: 'el-icon-goods',
        component: () => import('@/views/dept/jobDuty'),
        meta: { title: '职务设置', icon: 'table' }
      },
      {
        id: 11,
        path: 'workAddress',
        name: 'WorkAddress',
        title: '工作地点设置',
        icon: 'el-icon-c-scale-to-original',
        component: () => import('@/views/dept/workAddress'),
        meta: { title: '工作地点设置', icon: 'table' }
      },
    ]
  },
  {
    id: 12,
    path: '/user',
    component: Layout,
    redirect: '/user/table',
    name: 'user',
    title: '员工管理',
    icon: 'el-icon-user-solid',
    meta: { title: '员工管理', icon: 'example' },
    children: [
      {
        id: 13,
        path: 'userList',
        name: 'UserList',
        title: '员工设置',
        icon: 'el-icon-user',
        component: () => import('@/views/user/index'),
        meta: { title: '员工设置', icon: 'table' }
      },{
        id: 14,
        path: 'job',
        name: 'Job',
        title: '社会职业/职称设置',
        icon: 'el-icon-s-open',
        component: () => import('@/views/user/job'),
        meta: { title: '社会职业/职称设置', icon: 'table' }
      },
      {
        id: 15,
        path: 'jobOffice',
        name: 'JobOffice',
        title: '执业科室设置',
        icon: 'el-icon-s-platform',
        component: () => import('@/views/user/jobOffice'),
        meta: { title: '执业科室设置', icon: 'table' }
      },
      {
        id: 16,
        path: 'jobType',
        name: 'JobType',
        title: '工作类型设置',
        icon: 'el-icon-s-cooperation',
        component: () => import('@/views/user/jobType'),
        meta: { title: '工作类型设置', icon: 'table' }
      },
      {
        id: 17,
        path: 'auditFlow',
        name: 'AuditFlow',
        title: '审批流设置',
        icon: 'el-icon-check',
        component: () => import('@/views/user/auditFlow'),
        meta: { title: '审批流设置', icon: 'table' }
      },
    ]
  },
  {
    id: 18,
    path: '/dictionary',
    component: Layout,
    redirect: '/dictionary/table',
    name: 'dictionary',
    title: '字典管理',
    icon: 'el-icon-notebook-1',
    meta: { title: '字典管理', icon: 'example' },
    children: [
      {
        id: 19,
        path: 'form',
        name: 'Form',
        title: '剂型',
        icon: 'el-icon-tickets',
        component: () => import('@/views/dictionary/form'),
        meta: { title: '剂型', icon: 'table' }
      },{
        id: 20,
        path: 'unit',
        name: 'Unit',
        title: '单位',
        icon: 'el-icon-tickets',
        component: () => import('@/views/dictionary/unit'),
        meta: { title: '单位', icon: 'table' }
      },
    ]
  },
]

// export const constantRoutes = [
//   {
//     path: '/redirect',
//     component: Layout,
//     hidden: true,
//     children: [
//       {
//         path: '/redirect/:path(.*)',
//         component: () => import('@/views/redirect')
//       }
//     ]
//   },
//   {
//     path: '/login',
//     component: () => import('@/views/login'),
//     hidden: true
//   },
//   {
//     path: '/register',
//     component: () => import('@/views/register'),
//     hidden: true
//   },
//   {
//     path: '/404',
//     component: () => import('@/views/error/404'),
//     hidden: true
//   },
//   {
//     path: '/401',
//     component: () => import('@/views/error/401'),
//     hidden: true
//   },
//   {
//     path: '',
//     component: Layout,
//     redirect: 'index',
//     children: [
//       {
//         path: 'index',
//         component: () => import('@/views/index'),
//         name: 'Index',
//         meta: { title: '首页', icon: 'dashboard', affix: true }
//       }
//     ]
//   },
//   {
//     path: '/user',
//     component: Layout,
//     hidden: true,
//     redirect: 'noredirect',
//     children: [
//       {
//         path: 'profile',
//         component: () => import('@/views/system/user/profile/index'),
//         name: 'Profile',
//         meta: { title: '个人中心', icon: 'user' }
//       }
//     ]
//   }
// ]

// 动态路由，基于用户权限动态去加载
export const dynamicRoutes = [
  {
    path: '/system/user-auth',
    component: Layout,
    hidden: true,
    permissions: ['system:user:edit'],
    children: [
      {
        path: 'role/:userId(\\d+)',
        component: () => import('@/views/system/user/authRole'),
        name: 'AuthRole',
        meta: { title: '分配角色', activeMenu: '/system/user' }
      }
    ]
  },
  {
    path: '/system/role-auth',
    component: Layout,
    hidden: true,
    permissions: ['system:role:edit'],
    children: [
      {
        path: 'user/:roleId(\\d+)',
        component: () => import('@/views/system/role/authUser'),
        name: 'AuthUser',
        meta: { title: '分配用户', activeMenu: '/system/role' }
      }
    ]
  },
  {
    path: '/system/dict-data',
    component: Layout,
    hidden: true,
    permissions: ['system:dict:list'],
    children: [
      {
        path: 'index/:dictId(\\d+)',
        component: () => import('@/views/system/dict/data'),
        name: 'Data',
        meta: { title: '字典数据', activeMenu: '/system/dict' }
      }
    ]
  },
  {
    path: '/monitor/job-log',
    component: Layout,
    hidden: true,
    permissions: ['monitor:job:list'],
    children: [
      {
        path: 'index/:jobId(\\d+)',
        component: () => import('@/views/monitor/job/log'),
        name: 'JobLog',
        meta: { title: '调度日志', activeMenu: '/monitor/job' }
      }
    ]
  },
  {
    path: '/tool/gen-edit',
    component: Layout,
    hidden: true,
    permissions: ['tool:gen:edit'],
    children: [
      {
        path: 'index/:tableId(\\d+)',
        component: () => import('@/views/tool/gen/editTable'),
        name: 'GenEdit',
        meta: { title: '修改生成配置', activeMenu: '/tool/gen' }
      }
    ]
  }
]

// 防止连续点击多次路由报错
let routerPush = Router.prototype.push;
let routerReplace = Router.prototype.replace;
// push
Router.prototype.push = function push(location) {
  return routerPush.call(this, location).catch(err => err)
}
// replace
Router.prototype.replace = function push(location) {
  return routerReplace.call(this, location).catch(err => err)
}

export default new Router({
  mode: 'history', // 去掉url中的#
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})
